/*
 * @Author: ChunLai
 * @Date: 2022-03-30 17:37:12
 * @LastEditTime: 2025-08-29 11:54:25
 * @Description: 数据字典配置
 * @FilePath: \02.bldinsure\src\store\modules\dictionary.js
 */
import appDits from "@/config/app.js";
import userDits from "@/config/user.js";

const state = {
  /* ===== 各家保司特殊字段 ===== */
  //有效期长期默认值
  longTime: "9999-12-31",
  // 出生证是否限制有效期 -1-自选 1-固定3周岁前一天 2固定出生日期+2 3固定出生日期+3 4-固定4周岁前一天  9999长期
  idType11ValidFixed: -1,
  // 户口簿是否限制有效期 -1-自选 1-固定16周岁前一天 2固定出生日期+16 9999长期
  idType3ValidFixed: -1,
  birthAddValue: 0,
  gysFullName: "", // 产品保司全名

  /* ===== 单字段配置 ===== */
  normalOcuu: ["学生", "儿童"],
  normalOcuuKey: "name",
  ocuuClassName: "类",
  occupationDesc: "",
  provinceFilter: false, //投被保人联系地址根据业务员地址进行限制过滤
  provinceFilterArr: ["areaName"],
  detailAddrRule: "村/组/号/室/队/院/房/楼/栋",
  noneOcrCheckIdCard: false, // 不需要ocr识别证件照信息(默认false需要)
  adultAgeStandard: 18, // 成年人年龄最小值

  /* ===== 各家保司选择列表 ===== */
  /* = 常规通用码表(不可配置) = */
  crsIdTypeList: userDits.crsList, // 个税居民类型
  residentTypeList: userDits.residentList, //居民类型
  IncSourceList: userDits.incomeSourceList, // 收入来源
  bnfTypeList: userDits.bnfTypeList,
  payModeList: appDits.payChnList, // 缴费方式
  contractTypeList: appDits.printList, //保单类型
  idTypeList: [
    {
      keyId: "0",
      text: "身份证",
      bbr: true,
      syr: true,
      tbr: true,
    },
  ],
  relationship: [
    {
      keyId: "0",
      text: "配偶",
      bbr: true,
      syr: true,
    },
  ],
  bbrToMainBbr: [], //被保人是主被保险人的
  bankList: [],
  nationList: [],
  maritalStatusList: [],
  degreeList: [],
  housesEquityList: [],
  hospitalCodeList: [],
  selfFieldDesc:
    "满足下列条件之一的，均定义为自保件：<br />①销售人员作为投保人、被保人或受益人（含本单销售人员所在公司其他销售人员)；<br />②销售人员的直系亲属作为投保人、被保人或受益人（直系血亲和直系姻亲，如配偶、父母、子女、祖父母、外祖父母、孙子女、外孙子女）", // 自保件释义
  // 乐橙:投保人应在对所有被保险人健康/职业状况充分了解的基础上履行如实告知义务。投保人承诺完全知晓所有被保险人健康/职业状况，并如实告知。若被保险人健康/职业状况与告知内容不符：（1）一经发现，本公司将依据法律解除合同。（2）若发生保险事故，本公司不承担赔偿或给付保险金的责任，并将依据法律解除合同，同时根据投保人不如实告知情况不退还保险费。
  healthyTips:
    "依据《中华人民共和国保险法》的有关规定，保险公司就被保险人有关情况的询问，投保人应当履行如实告知义务，否则保险公司有权依法解除保险合同，并对保险合同解除前发生的保险事故不承担保险责任。投保人故意或者因重大过失未履行前款规定的如实告知义务，足以影响保险人决定是否同意承保或者提高保险费率的，保险人有权解除合同。", //告知页头部提示信息
  /* 自保件代理人告知配置 */
  selfInsuredShipRegions: [], // 替换整合 ship1Province + relationship1(百年)
  selfInsuredRegions: [], //自保件区域配置(长城+百年+利安)
  selfInsuredTip: {}, // 展示拍照图片示例及文字说明(长城+利安)
  selfInsuredPhotos: {}, // 图片字段名
  crsTaxPlace: [],
  // 税收声明填写
  taxFileKeys: {
    lastName: "",
    fitstName: "",
    crsIdType: "",
    homeAddressCHN: "",
    homeAddressEN: "",
    placeOfBirthCHN: "",
    placeOfBirthEN: "",
    taxCountyAndNos: "",
    taxNum2: "",
    taxNum3: "",
    noTaxNoReasonDetail: "",
    noTaxNoReason: "",
    birthCity: "",
    birthNativePlace: "",
    birthNativePlaceName: "",
    birthProvince: "",
    currentCity: "",
    currentNativePlace: "",
    currentNativePlaceName: "",
    currentProvince: "",
    taxIdentInfo: {},
  },
  /* === 授权确认模块 === */
  // 银行自动转账授权书(长城)
  bankTransferAuthorization: {},
  /**客户信息导入*/
  customerInfos: "1",
  autoRenewalFile: {},
  msBankIcons: {},
};

const getters = {
  ditCodeState: (state) => state,
  longTime: (state) => state.longTime,
  gysFullName: (state) => state.gysFullName,
  idType3ValidFixed: (state) => state.idType3ValidFixed,
  idType11ValidFixed: (state) => state.idType11ValidFixed,
  customerInfos: (state) => state.customerInfos,
  autoRenewalFile: (state) => state.autoRenewalFile,
  /**固定选择码表*/
  sexList: () => appDits.sexList,
  renewList: () => appDits.xubaoList,
  exModeList: () => appDits.exModeList,
  autoPayList: () => appDits.autoPayList,
  yesNoCheckList: () => appDits.yesNoList,
  aliveModeList: () => appDits.authorizeList,
  bcardTypeList: () => appDits.bcardTypeList,
  dateEndList: () => appDits.dateEndList,
  socialSecList: () => userDits.shebaoList,
  holderTypeList: () => userDits.holderList,
  /**固定选择码表*/
  bnfTypeList: (state) => state.bnfTypeList,
  selfInsuredRegions: (state) => state.selfInsuredRegions,
  selfInsuredShipRegions: (state) => state.selfInsuredShipRegions,
  selfInsuredPhotos: (state) => state.selfInsuredPhotos,
  selfInsuredTip: (state) => state.selfInsuredTip,
  contractTypeList: (state) => state.contractTypeList,
  taxFileKeys: (state) => state.taxFileKeys,
  nationList: (state) => state.nationList,
  crsTaxPlace: (state) => state.crsTaxPlace,
  detailAddrRule: (state) => state.detailAddrRule,
  idTypeList: (state) => state.idTypeList,
  // 客户证件类型
  applicantIdTypeList: (state) => {
    return state.idTypeList.filter((item) => item.tbr || item.tbr !== false);
  },
  insuredIdTypeList: (state) => {
    return state.idTypeList.filter((item) => item.bbr || item.bbr !== false);
  },
  benefitIdTypeList: (state) => {
    return state.idTypeList.filter((item) => item.syr || item.syr !== false);
  },
  // 客户投保关系
  relationship: (state) => state.relationship,
  bbrToMainBbr: (state) => state.bbrToMainBbr,
  insuredRelationship: (state) => {
    return state.relationship.filter((item) => item.bbr || item.bbr !== false);
  },
  bbrWithJhrShip: (state) => {
    return state.relationship.filter((item) => item.jhr || item.jhr !== false);
  },
  benefitRelationship: (state) => {
    return state.relationship.filter((item) => item.syr || item.syr !== false);
  },

  maritalStatusList: (state) => state.maritalStatusList,
  IncSourceList: (state) => state.IncSourceList,
  degreeList: (state) => state.degreeList,
  fastDegree: (state) => {
    let list = state.degreeList.filter((item) => item.fast);
    return list;
  },
  fastmaritalStatus: (state) => {
    let list = state.maritalStatusList.filter((item) => item.fast);
    return list;
  },
  crsIdTypeList: (state) => state.crsIdTypeList,
  residentTypeList: (state) => state.residentTypeList,
  housesEquityList: (state) => state.housesEquityList,
  hospitalCodeList: (state) => state.hospitalCodeList,

  // 保单页-银行卡
  bankList: (state) => state.bankList,
  bankR: (state) => state.bankList.filter((item) => item.bankR),
  bank7: (state) => state.bankList.filter((item) => item.bank7),
  payModeList: (state) => state.payModeList,

  normalOcuu: (state) => state.normalOcuu,
  normalOcuuKey: (state) => state.normalOcuuKey,
  ocuuClassName: (state) => state.ocuuClassName,
  occupationDesc: (state) => state.occupationDesc,
  healthyTips: (state) => state.healthyTips,
  selfFieldDesc: (state) => state.selfFieldDesc,

  provinceFilter: (state) => state.provinceFilter,
  provinceFilterArr: (state) => state.provinceFilterArr,
  noneOcrCheckIdCard: (state) => state.noneOcrCheckIdCard,
  adultAgeStandard: (state) => state.adultAgeStandard,
  bankTransferAuthorization: (state) => state.bankTransferAuthorization,
};

const mutations = {
  INIT_DATA(state, payload) {
    Object.assign(state, payload);
  },
  SET_BANK_ICON(state, payload) {
    state.msBankIcons = payload;
  },
  SET_COUNTRY_LIST(state, payload) {
    state.nationList = payload;
  },
};
const actions = {
  async initDictionaryCode({ state, commit, dispatch }, data) {
    commit("INIT_DATA", data);
    dispatch("getGuoJiaJson", data);
    /* === 民盛通用码表配置 === */
    // 1.银行码表
    if (data.bankList && data.bankList.length > 0) {
      let defBankCfg = {};
      if (state.msBankIcons.domainUrl) {
        defBankCfg = JSON.parse(JSON.stringify(state.msBankIcons));
      } else {
        defBankCfg = await dispatch("json/getJson9Config", "msBankCodes", {
          root: true,
        });
        commit("SET_BANK_ICON", defBankCfg);
      }
      // console.log(defBankCfg);
      let banks = data.bankList.map((item) => {
        const fd = defBankCfg.codelist.find((ele) => ele.keyId === item.keyId);
        if (fd) {
          item.img = `${defBankCfg.domainUrl}${fd.img || ""}`;
          item.text = fd.text;
        }
        return item;
      });
      commit("INIT_DATA", {
        bankList: banks,
      });
    }
    // 2.居民税收类型
    let sslist = [];
    if (data.shuiShouArr && data.shuiShouArr.length > 0) {
      sslist = userDits.crsList.filter((item) =>
        data.shuiShouArr.includes(item.keyId)
      );
    }
    if (data.crsIdTypeList && data.crsIdTypeList.length > 0) {
      sslist = data.crsIdTypeList;
    }
    // console.log(sslist);
    if (sslist.length > 0) {
      commit("INIT_DATA", {
        crsIdTypeList: sslist,
      });
    }
    // 3.缴费
    if (data.jiaofeiArr && data.jiaofeiArr.length > 0) {
      let jflist = appDits.payChnList.filter((item) =>
        data.jiaofeiArr.includes(item.value)
      );
      // console.log(jflist);
      commit("INIT_DATA", {
        payModeList: jflist,
      });
    }
    // 4.保单
    if (data.hetongArr && data.hetongArr.length > 0) {
      commit("INIT_DATA", {
        contractTypeList: data.hetongArr,
      });
    }
    if (data.hetongCodeArr && data.hetongCodeArr.length > 0) {
      let bdlist = appDits.printList.filter((item) =>
        data.hetongCodeArr.includes(item.value)
      );
      // console.log(jflist);
      commit("INIT_DATA", {
        contractTypeList: bdlist,
      });
    }
  },
  // 5.国籍
  getGuoJiaJson({ state, commit, dispatch }, data = {}) {
    if (data.nationList && data.nationList.length > 0) {
      commit("SET_COUNTRY_LIST", data.nationList);
    } else {
      if (state.nationList.length > 0) return;
      dispatch("json/getJson9Config", "country", {
        root: true,
      }).then((res) => {
        commit("SET_COUNTRY_LIST", res);
      });
    }
  },
};

export default {
  namespaced: true,
  state,
  getters,
  mutations,
  actions,
};
